﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;

namespace Barry.BarbeSystem.Core
{
    public class Utility
    {
        public const int PageCount = 10;
        private static byte[] IV = { 0x13, 0x55, 0x77, 0x88, 0x41, 0x55 };

        private static  string keys = "whyzhn";

        public static  string EncrptDES(string encryString)
        {
            byte[] keysByte = Encoding.UTF8.GetBytes(keys);
            byte[] inputStringByte = Encoding.UTF8.GetBytes(encryString);
                  DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
            MemoryStream  mStream= new MemoryStream();
            CryptoStream  cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(keysByte, IV),CryptoStreamMode.Write);

            cStream.Write(inputStringByte,0, inputStringByte.Length);
            cStream.Flush();
            return Convert.ToBase64String(mStream.ToArray());
        }

        public static string DecryptDES(string decryptString)
        {
            byte[] rgbKey = Encoding.UTF8.GetBytes(keys);

            byte[] inputByteArray = Convert.FromBase64String(decryptString);
            DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider();
            MemoryStream mStream = new MemoryStream();
            CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, IV), CryptoStreamMode.Write);
            cStream.Write(inputByteArray, 0, inputByteArray.Length);
            cStream.FlushFinalBlock();
            return Encoding.UTF8.GetString(mStream.ToArray());
        }

    }
}